<?php
include 'connexionobligatoire.php';
include 'debut.php';
include 'connexion.php';

echo "<div id='contenu'>\n";
echo "<form method=\"post\" action=\"deconnexion.php\" style=\"text-align:right;\">\n<input type=\"submit\" value=\"Deconnexion\" /><br/>\n</form>\n";
echo "<h2><p style=\"color:#321b15;\">Acceuil administration</p></h2>\n";

if(isset($_POST['login'])){
	$login=$_POST['login'];
	$nom=$_POST['nom'];
	$prenom=$_POST['prenom'];
	$mail=$_POST['mail'];
	mysql_query("UPDATE users SET loginUser='$login',nomUser='$nom',prenomUser='$prenom',emailUser='$mail' WHERE loginUser='".$_SESSION['Id']."'");
	$_SESSION['Id']=$_POST['login'];
}
if(isset($_POST['login2'])){
	$login=$_POST['login2'];
	$nom=$_POST['nom'];
	$prenom=$_POST['prenom'];
	$mail=$_POST['mail'];
	mysql_query("UPDATE users SET loginUser='$login',nomUser='$nom',prenomUser='$prenom',emailUser='$mail' WHERE idUser='".$_POST['loginbase']."'");
}
if(isset($_POST['login3'])){
	$login=$_POST['login3'];
	$nom=$_POST['nom'];
	$prenom=$_POST['prenom'];
	$mail=$_POST['mail'];
	$mdp=$_POST['mdp'];
	mysql_query("INSERT INTO users VALUES ('','$login','$nom','$prenom','$mail','$mdp')");
	echo "<script>alert('ok');</script>";
}

$requete=mysql_query("SELECT idUser from users WHERE loginUser='".$_SESSION['Id']."'");
$id=mysql_fetch_array($requete);

$requete2=mysql_query("SELECT * from users");
?>
<table id="admin">
	<tr>
	<th>Gestion du compte</th>
<?php
	if($id[0]==1)
	{
		echo "<th>Gestion des utilisateurs</th>";
	}
?>
	</tr>
	<tr>
	<td>
			<a href="changemdp.php">Modifier mot de passe</a><br/>
			<a href="changeinfo.php">Modifier information personnelles</a><br/>
			
	</td>
<?php
	if($id[0]==1)
	{
		
		echo "<td>";
		echo "<a href='newuser.php' class='ajout'>Ajouter un utilisateur</a><br/>";
		while($table2=mysql_fetch_array($requete2)){
			echo "<a href='modifadmin.php?id=".$table2['idUser']."'>".$table2['nomUser']." ".$table2['prenomUser']."</a><br/>";
		}
		echo "</td>";
		
	}
?>	
</tr>
</table>

<?php
echo "</div>";
include 'pied.php';
?>

</body>
</html>
